$input_list_file = $ARGV[0];
chomp($input_list_file);
$input_file = $ARGV[1];
chomp($input_file);
$pos = $ARGV[2];
$output_file = $ARGV[3];
chomp($pos);
chomp($output_file);
open(BUFF,$input_list_file);
$k =0;
while($line = <BUFF>)
{
	chomp($line);
	$hash{$line} = $k;
	$k++;
}
open(BUFF,$input_file);
open(WRBUFF,">$output_file");
while($line = <BUFF>)
{
	chomp($line);
	@array = split(" ",$line);
	if($array[0] == 23)
	{
		$array[0] = "X";
	}
	if($array[0] == 24)
        {
                $array[0] = "Y";
        }
	if($array[0] == 26)
        {
                $array[0] = "M";
        }

	if(exists($hash{$array[$pos-1]}))
	{
		
		$array_out[$hash{$array[$pos-1]}] = $array[0]." ".$array[1]." ".$array[2]." ".$array[3];
	}
	else
	{
		die "inputlist file and input file are not related\n";
	}
}
for($i=0;$i<@array_out;$i++)
{

	print WRBUFF $array_out[$i]."\n";
}
